﻿using System.Windows.Documents;
using DiagramDesigner.Common.Controls;
using System.Windows.Interactivity;

namespace Behavior.Resize
{
    public class ResizeBehavior : Behavior<DesignerItem>
    {
        private DesignerShape _shape;
        private ResizeAdorner _adorner;

        public ResizeBehavior()
        {
            
        }

        protected override void OnAttached()
        {
            base.OnAttached();
            var di = AssociatedObject.Content as DesignerItem;
            _shape = di.Content as DesignerShape;
            if (_shape == null) return;
            _adorner = new ResizeAdorner(AssociatedObject);
            AdornerLayer.GetAdornerLayer(AssociatedObject).Add(_adorner);
        }

        protected override void OnDetaching()
        {
            base.OnDetaching();
            if (_adorner == null) return;
            AdornerLayer.GetAdornerLayer(AssociatedObject).Remove(_adorner);
        }
    }
}
